
#include "n32l40x.h"
#include "my_adc_drv.h"


// PC1 ---充电检测 开下拉电阻，（可以不用开内部电阻）
// PC2 ---充满检测 ---充满时为高电平（开内部下拉电阻）



// #define DC_5V_CHECK_PORT            (GPIO_C)
// #define DC_5V_CHECK_PIN             (GPIO_PIN_1)

// #define IS_5V_IN()                  (gpio_read_pin(DC_5V_CHECK_PORT, DC_5V_CHECK_PIN))

// #define BAT_CHARG_FULL_PORT         (GPIO_C)
// #define BAT_CHARG_FULL_PIN          (GPIO_PIN_2)
// #define IS_BAT_CHARGE_FULL()        (gpio_read_pin(BAT_CHARG_FULL_PORT, BAT_CHARG_FULL_PIN))

#define ADC_BUFF_MAX_CNT            (20)

typedef enum{
    IDLE_STA = 0,
    WORKING_STA,
    CHARGING_STA,
    CHARG_FULL_STA,
}BAT_STATUS_e;

typedef enum{
    LEVEL_EMETY = 0,
    LEVEL_LOW,
    LEVEL_MID,
    LEVEL_FULL,
}BAT_LEVEL_e;



typedef struct my_battery
{
    /* data */
    uint8_t charge_flag;
    uint8_t charge_full_flag;
    uint8_t adc_buff_index;

    BAT_STATUS_e sta;
    BAT_LEVEL_e level;
    uint16_t bat_voltage;   // 扩大100倍，如3.95v  ---395；
    uint32_t bat_adc_buff[ADC_BUFF_MAX_CNT];

}BAT_PARAM_t;



void my_battery_status_check(void);

int battery_charge_sta_get(void);

void my_battery_scanf(void);
void my_battery_deinit(void);
void my_battery_init(void);